
import numpy as np
import json
import pandas
import tensorflow as tf
import ast
from 数据处理 import 数组滑窗

def load(dataPath, 方向):
    print('---原始数据加载路径: ' + dataPath)

    pd_reader = pandas.read_csv(dataPath, sep=';', encoding='utf-8')

    # 使用ast 将字符串 转 数组  -- 太慢
    # keys = pd_reader.keys()
    # for i in range(1, len(keys)):
    #     pd_reader[keys[i]].apply(ast.literal_eval)

    # 转置成横向的
    if 方向 == "纵向":
        pd_reader = pd_reader.T

    # 按行取 字符串 使用json 转为数组
    # 跳过第一行时间
    source = pd_reader.values[1:]
    data = np.zeros([source.shape[0], source.shape[1], len(json.loads(source[0][0]))])
    # 遍历数组 字符串 使用json 转 array
    for i in range(len(data)):
        for j in range(len(data[i])):
            data[i][j] = json.loads(source[i][j])

    # 案行取 字符串 使用json 转为数组
    # data = pd_reader.values[1:]
    # for i in range(len(data)):
    #     line = data[i]
    #     newline = []
    #     # 自动跳过第一列名称
    #     for j in range(len(line)):
    #         newline.append(json.loads(line[j]))
    #     data[i] = newline
    # 按列取 字符串 使用json 转为数组
    # data = pd_reader.columns[1:]
    # for i in range(len(data)):
    #     line = pd_reader.get(data[i]).tolist()
    #     newline = []
    #     # 第一列名称
    #     for j in range(len(line)):
    #         newline.append(json.loads(line[j]))
    #     data[i] = newline

    # 滑窗切分
    num_classes, offset, x_train, y_train = 数组滑窗.横向滑窗_引用(data, 511, 2)
    return num_classes, offset, x_train, y_train



if __name__ == '__main__':
    load("../temp/data/通信达/分钟线.csv", "纵向")
    # load("纵向数组测试数据.csv", "纵向")
    # load("横向数组测试数据.csv", "横向')
